<template>
  <div>
    <!------------- 搜索 ----------->
    <div>
      <el-form
        style="max-width: 600px; display: flex"
        :model="seachData"
        status-icon
        label-width="auto"
        class="demo-ruleForm"
      >
        <el-form-item label="地图编号">
          <el-input
            v-model="seachData['number']"
            style="width: 145px"
            type="text"
            placeholder="请输入地图编号"
          />
        </el-form-item>
        <el-form-item label="地图名称" class="mg-left">
          <el-input
            v-model="seachData['name']"
            style="width: 145px"
            type="text"
            placeholder="请输入地图名称"
          />
        </el-form-item>
        <el-button type="primary" class="mg-left" @click="serchClick"
          >搜索</el-button
        >
      </el-form>
    </div>

    <el-button type="danger" @click="controls('add')">地图上传</el-button>

    <!------------- 表格 ----------->
    <el-table :data="tableData" border style="width: 100%" class="mt-3">
      <template #empty>
        <el-empty description="空空如也" :image-size="60" />
      </template>
      <el-table-column
        v-for="(item, index) in columns"
        :key="index"
        :prop="item.prop"
        :label="item.label"
      />
      <el-table-column label="修改时间">
        <template #default="{ row }">
          <div>{{ getTime(row.updateTime) }}</div>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        align="center"
        label="操作"
        min-width="152"
      >
        <template #default="{ row }">
          <el-button type="primary" link @click="controls('edit', row)"
            >编辑</el-button
          >
          <el-button type="success" link @click="controls('markers', row)"
            >标记</el-button
          >
          <el-button type="warning" link @click="controls('derive', row)"
            >导出</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      v-model:current-page="pagination.currentPage"
      v-model:page-size="pagination.pageSize"
      class="pagin"
      :locale="zhCn"
      size="small"
      :page-sizes="[10, 20, 50, 100]"
      layout="prev, pager, next, jumper,sizes,total"
      :total="pagination.total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
    <!-- 新增、编辑弹窗 -->
    <EditPop
      v-model="uploadShow"
      :soleItem="soleItem"
      @saveChange="serchClick"
    />
    <!-- 图标弹窗 -->
    <Markers :soleItem="soleItem" v-model="markShow" />
  </div>
</template>

<script setup lang="ts">
import EditPop from "./editPop.vue";
import Markers from "./markers/index.vue";
import { ref, reactive, onMounted } from "vue";
import { useGoodsExamine } from "./utils/hook";
// import { getDataList } from "@/api/uploadMap";
const { columns, pagination, getTime, getData, tableData, seachData } =
  useGoodsExamine();

const uploadShow = reactive<any>({ isShow: false, isEdit: false });
const markShow = reactive<any>({ isShow: false });
const soleItem = ref<Object>({});

onMounted(() => {
  getData(seachData.value);
});

const controls = (e: any, item: Object) => {
  if (e === "add" || e === "edit") {
    uploadShow["isShow"] = true;
    uploadShow["isEdit"] = e !== "add";
  }
  if (e === "markers") markShow["isShow"] = true;
  soleItem.value = item;
};
const serchClick = () => {
  getData(seachData.value);
};
const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`);
};
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`);
};
</script>

<style lang="scss" scoped>
.mg-left {
  margin-left: 50px;
}
// 分页样式
.pagin {
  margin-top: 20px;
  display: flex;
  justify-content: end;
}
</style>
